﻿
using Controller.i18n.plc.crane;
using HBase;
using hconnect;
using hCommand;
using Persistence;
using System.Collections.Generic;

namespace Controller
{
    public class Wcs2WmsStatus : ZtTask
    {
        public Wcs2WmsStatus()
        {
            time = 500;
        }
        ICoreWhLocServer locServer = WMSDalFactray.getDal<ICoreWhLocServer>();
        protected IWCSServer taskServer;
        Dictionary<int, int> craneStatus = new Dictionary<int, int>();
        BParam b = null;
        protected override bool init()
        {

            craneStatus[0] = 0;
            craneStatus[1] = 0;
            taskServer = WMSDalFactray.getDal<IWCSServer>();
            return true;
        }
        protected override bool onlyOneTimeAsync()
        {
            b = taskServer.getById<BParam>(100);
            return true;
        }
        public override bool excute()
        {

            bool res = false;
            res = res || CraneStatus(1);
            res = res || CraneStatus(2);
            int v = 3;
            if (b.v != v)
            {
                b.v = v;
                taskServer.update(b);
            }

            return res;
        }

        protected bool CraneStatus(int driveId)
        {


            CraneStatus csb = (CraneStatus)StatusCache.getStatus<CraneSynchro>(driveId);
            if (csb == null)
            {
                return false;
            }
            int status = 0;
            if (!csb.isfault())
            {

                status = 1;
            }
            if (status != craneStatus[driveId - 1])
            {

                bool sucess = locServer.updateWcsAutoActive(driveId, status);
                if (sucess)
                {
                    craneStatus[driveId - 1] = status;
                }
            }
            return true;
        }








    }
}
